10 add vector
Uncomment the following line to install leafmap if needed.
In [1]:
# !pip install leafmap
How to add a shapefile, GeoJSON, and KML to the map
In [2]:
import leafmap
In [3]:
m = leafmap.Map()
m
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook

In [4]:
m = leafmap.Map(center=[0, 0], zoom=2)
in_geojson = 'https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/cable-geo.geojson'
m.add_geojson(in_geojson, layer_name="Cable lines")
m
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
m = leafmap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson"
m.add_geojson(url, layer_name="Countries", fill_colors=['red', 'yellow', 'green', 'orange'])
m
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [6]:
import random
m = leafmap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson"
def random_color(feature):
return {
'color': 'black',
'fillColor': random.choice(['red', 'yellow', 'green', 'orange']),
}
m.add_geojson(url, layer_name="Countries", style_callback=random_color)
m
Out[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [7]:
m = leafmap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson"
style = {
"stroke": True,
"color": "#0000ff",
"weight": 2,
"opacity": 1,
"fill": True,
"fillColor": "#0000ff",
"fillOpacity": 0.1,
}
hover_style = {"fillOpacity": 0.7}
m.add_geojson(url, layer_name="Countries", style=style, hover_style=hover_style)
m
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
m = leafmap.Map(center=[0, 0], zoom=2)
in_shp = '../data/countries.shp'
m.add_shp(in_shp, layer_name="Countries")
m
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [9]:
m = leafmap.Map()
in_kml = '../data/us-states.kml'
m.add_kml(in_kml,layer_name="US States KML")
m
Out[9]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [10]:
m = leafmap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/countries.geojson"
m.add_vector(url, layer_name="Countries", fill_colors=['red', 'yellow', 'green', 'orange'])
m
Out[10]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [11]:
m = leafmap.Map()
In [12]:
in_shp = '../data/countries.shp'
in_geojson = '../data/us-states.json'
in_kml = '../data/us-states.kml'
In [13]:
m.add_shp(in_shp, layer_name="Shapefile")
In [14]:
m.add_geojson(in_geojson, layer_name="GeoJSON")
In [15]:
m.add_kml(in_kml, layer_name="KML")
In [16]:
m
Out[16]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Last update: 2021-06-22